package com.sub.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sub.pojo.Category;
import com.sub.service.ICategoryService;
import com.sub.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Submerge.
 * @since 2022-11-04
 */
@RestController
@RequestMapping("/sub/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @GetMapping("/page")
    public R categoryPage(){
        IPage<Category> page = new Page<>(1,10);
        page = categoryService.page(page);
        return R.success(page);
    }

    @GetMapping("/detail/{id}")
    public R detailCategory(@PathVariable String id){
        return R.success(categoryService.getById(id));
    }



    @PostMapping("/save")
    public R saveCategory(@RequestBody Category category){
        categoryService.save(category);
        return R.success("新增成功");
    }

    @PutMapping("/update")
    public R updateCategory(@RequestBody Category category){
        categoryService.updateById(category);
        return R.success("修改成功！");
    }

    @DeleteMapping("/delete/{id}")
    public R deleteCategory(@PathVariable String id){
        categoryService.removeById(id);
        return R.success("删除成功！");
    }


}

